﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
using System.Data.SqlClient;

namespace DiChanAPI.Controllers
{
    public class SysDictionaryController : ApiController
    {
        #region 字典表类型显示

        // GET api/sysdictionary
        [HttpGet]
        [ActionName("GetDictionary")]
        public IEnumerable<SysDictionary> GetDictionary(int? name)
        {
            if (name == null)
            {
                return new SysDictionaryBLL().GetList();
            }
            else
            {
                return new SysDictionaryBLL().GetList().Where(n => n.Dictionary_Type==name);
            }
        }

        #endregion
        // GET api/sysdictionary/5
        public string Get(int id)
        {
            return "value";
        }
        #region 字典类型添加

        /// <summary>
        /// 字典类型添加
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionName("GetDictionary")]
        // POST api/sysdictionary
        public bool Post([FromBody]SysDictionary dic)
        {

            int num = Convert.ToInt32(new SysDictionaryBLL().GetLastList(dic).FirstOrDefault().Dictionary_Number);

            SqlParameter[] par ={
                                    new SqlParameter("@Dictionary_Number",(num+1).ToString()),
                                    new SqlParameter("@Dictionary_Type",dic.Dictionary_Type),
                                    new SqlParameter("@Dictionary_Name",dic.Dictionary_Name),
                                    new SqlParameter("@Dictionary_CreatePeople",dic.Dictionary_CreatePeople),
                                    new SqlParameter("@Dictionary_CreateTime",DateTime.Now.Date),
                                    new SqlParameter("@Dictionary_ParentId",0),
                                };
            return new SysDictionaryBLL().Add(par);

        }

        #endregion

        // PUT api/sysdictionary/5
        public void Put(int id, [FromBody]string value)
        {

        }

        // DELETE api/sysdictionary/5
        public void Delete(int id)
        {
        }
    }
}
